package ${artifactId}.service.${moduleName}.impl;

import com.ahccc.common.util.StrUtil;
import com.ahccc.common.util.bootStrapTable.PageVO;
import com.ahccc.data.service.GenericManagerImpl;
import com.ahccc.data.utils.FieldFilter;
import com.ahccc.data.utils.QueryFilter;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.stereotype.Service;
import org.springframework.beans.factory.annotation.Autowired;
import ${artifactId}.model.${moduleName}.${name};
import ${artifactId}.repository.${moduleName}.${name}Dao;
import ${artifactId}.service.${moduleName}.${name}Manager;
import java.util.HashMap;
import java.util.Map;
/**
* @copyright:${copyright}
* @Author:${author}
* @Date:${datetime}
* @Description:
*/
@Service
public class ${name}ManagerImpl extends GenericManagerImpl<${name}, <#list pks as f>${f.javaType} </#list>> implements ${name}Manager {

	${name}Dao ${sname}Dao;

	@Autowired
	public ${name}ManagerImpl(${name}Dao genericDao) {
		super(genericDao);
		${sname}Dao = genericDao;
	}

	@Override
	public PageVO findAll(${name} ${sname}, Sort sort, Integer pageNumber, Integer pageSize) {
		QueryFilter queryFilter = new QueryFilter();
		<#list fields as f >
        if (!StrUtil.isEmpty(${sname}.get${f.fixCode}())){
        	queryFilter.add("${f.simpleName}", FieldFilter.OP.EQ, ${sname}.get${f.fixCode}());
        }
		</#list>
		Pageable pageable =PageRequest.of(pageNumber - 1, pageSize, sort);
		Page<${name}> list = dao.findAll(queryFilter.toArray(), pageable);
	    return new PageVO(list.getContent(), (int) list.getTotalElements());
	}

	@Override
	public Map<String, Object> pagingByVue(${name} ${sname}, Sort sort, Integer pageNumber, Integer pageSize) {
		QueryFilter queryFilter = new QueryFilter();
		<#list fields as f >
		if (!StrUtil.isEmpty(${sname}.get${f.fixCode}())){
			queryFilter.add("${f.simpleName}", FieldFilter.OP.EQ, ${sname}.get${f.fixCode}());
		}
		</#list>
		Pageable pageable =PageRequest.of(pageNumber - 1, pageSize, sort);
		Page<${name}> list = dao.findAll(queryFilter.toArray(), pageable);
		Map<String,Object> map=new HashMap<>();
		map.put("records",list.getContent());
		map.put("total",list.getTotalElements());
		map.put("size",pageSize);
		map.put("current",pageNumber);
		map.put("searchCount",true);
		map.put("pages",list.getTotalPages());
		return map;
	}

}
